package com.ruoyi.project.im.avatar.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.im.avatar.domain.VisitorAvatar;
import com.ruoyi.project.im.avatar.service.IVisitorAvatarService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * AvatarController
 * 
 * @author ruoyi
 * @date 2023-02-18
 */
@Controller
@RequestMapping("/IM/avatar")
public class VisitorAvatarController extends BaseController
{
    private String prefix = "IM/avatar";

    @Autowired
    private IVisitorAvatarService visitorAvatarService;

    @RequiresPermissions("IM:avatar:view")
    @GetMapping()
    public String avatar()
    {
        return prefix + "/avatar";
    }

    /**
     * 查询Avatar列表
     */
    @RequiresPermissions("IM:avatar:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VisitorAvatar visitorAvatar)
    {
        startPage();
        List<VisitorAvatar> list = visitorAvatarService.selectVisitorAvatarList(visitorAvatar);
        return getDataTable(list);
    }

    /**
     * 导出Avatar列表
     */
    @RequiresPermissions("IM:avatar:export")
    @Log(title = "Avatar", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VisitorAvatar visitorAvatar)
    {
        List<VisitorAvatar> list = visitorAvatarService.selectVisitorAvatarList(visitorAvatar);
        ExcelUtil<VisitorAvatar> util = new ExcelUtil<VisitorAvatar>(VisitorAvatar.class);
        return util.exportExcel(list, "Avatar数据");
    }

    /**
     * 新增Avatar
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存Avatar
     */
    @RequiresPermissions("IM:avatar:add")
    @Log(title = "Avatar", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VisitorAvatar visitorAvatar)
    {
        return toAjax(visitorAvatarService.insertVisitorAvatar(visitorAvatar));
    }

    /**
     * 修改Avatar
     */
    @RequiresPermissions("IM:avatar:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VisitorAvatar visitorAvatar = visitorAvatarService.selectVisitorAvatarById(id);
        mmap.put("visitorAvatar", visitorAvatar);
        return prefix + "/edit";
    }

    /**
     * 修改保存Avatar
     */
    @RequiresPermissions("IM:avatar:edit")
    @Log(title = "Avatar", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VisitorAvatar visitorAvatar)
    {
        return toAjax(visitorAvatarService.updateVisitorAvatar(visitorAvatar));
    }

    /**
     * 删除Avatar
     */
    @RequiresPermissions("IM:avatar:remove")
    @Log(title = "Avatar", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(visitorAvatarService.deleteVisitorAvatarByIds(ids));
    }
}
